WTL Controls
|
Back to the WTL Controls Home Page. |
An owner-drawn CStatic descendant, providing custom background and text colors and edge styles. More...
#include <ODStatic.h>
Public Member Functions | |
CODStatic () noexcept | |
virtual | ~CODStatic () |
void | SubclassStatic (HWND hWnd) |
Subclass a Static Text control. More... | |
void | UnSubclassStatic () |
Un-subclass the window and release GDI resources. More... | |
void | SetBtnFaceBkgnd (bool value) |
Set or clear the UseBtnFaceBkgnd state. A call to UpdateContent may be required to make the new state apparent. More... | |
bool | GetBtnFaceBkgnd () const |
Default: false . More... | |
void | SetBackColor (COLORREF value) |
Set a new background color. A call to UpdateContent may be required to make the new color visible. More... | |
COLORREF | GetBackColor () const |
Default: COLOR_BTNFACE . More... | |
void | SetTextColor (COLORREF value) |
Set a new text color. A call to UpdateContent may be required to make the new color visible. More... | |
COLORREF | GetTextColor () const |
Default: COLOR_WINDOWTEXT . More... | |
void | SetCaption (LPCTSTR text) |
Set a new string to display. A call to UpdateContent may be required to make the new caption visible. More... | |
std::basic_string< TCHAR > | GetCaption () const |
Default: "". More... | |
void | SetMultilineEnabled (bool value) |
If false , the DT_SINGLELINE flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible. More... | |
bool | GetMultilineEnabled () const |
Default: false . More... | |
void | SetEndEllipsisEnabled (bool value) |
If true, the DT_END_ELLIPSIS flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible. More... | |
bool | GetEndEllipsisEnabled () const |
Default: false . More... | |
void | SetPathEllipsisEnabled (bool value) |
If true, the DT_PATH_ELLIPSIS flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible. More... | |
bool | GetPathEllipsisEnabled () const |
Default: false . More... | |
void | SetHorzTextAlignment (CHorzAlignment value) |
The CHorzAlignment member variable state will result in either the DT_CENTER, DT_LEFT or DT_RIGHT flag being included in calls to DrawText (or DrawThemeText), as appropriate. A call to UpdateContent may be required to make changes visible. More... | |
CHorzAlignment | GetHorzTextAlignment () const |
Default: CHorzAlignment::haMiddle . More... | |
void | SetVertTextAlignment (CVertAlignment value) |
The CVertAlignment member variable state will result in either the DT_BOTTOM, DT_TOP or DT_VCENTER flag being included in calls to DrawText (or DrawThemeText), as appropriate. A call to UpdateContent may be required to make changes visible. More... | |
CVertAlignment | GetVertTextAlignment () const |
Default: CVertAlignment::vaLeft . More... | |
void | SetEdgeStyle (CEdgeStyle style) |
The EdgeStyle state determines the type of graphic boundary indicator surrounding the control in it's parent dialog or property page. More... | |
CEdgeStyle | GetEdgeStyle () const |
Default: CEdgeStyle::esLine . More... | |
void | SetVerticalMargin (int margin) |
Sets top and bottom text margin inside window edge. A call to UpdateContent may be required to make changes visible. More... | |
int | GetVerticalMargin () const |
Default: 0. More... | |
void | SetHorizontalMargin (int margin) |
Sets left and right text margin inside window edge. A call to UpdateContent may be required to make changes visible. More... | |
int | GetHorizontalMargin () const |
Default: 0. More... | |
void | UseThemedStyle (bool val) |
If true , content will be painted using DrawThemeBackground and DrawThemeText, rather than the older FillRect and DrawText APIs. More... | |
bool | IsUsingThemedStyle () const |
Default: false . More... | |
void | SetThemedBackgroundStyle (CThemedBackgroundStyle val) |
Set the ThemedBackgroundStyle to a new value. More... | |
CThemedBackgroundStyle | GetThemedBackgroundStyle () const |
Default: tbMainInstructionPane . More... | |
void | SetThemedTextStyle (CThemedTextStyle val) |
Set the ThemedTextStyle to a new value. More... | |
CThemedTextStyle | GetThemedTextStyle () const |
Default: ttMainInstruction . More... | |
void | UpdateContent () |
Wraps calls to Invalidate and UpdateWindow, forcing a repaint, updating the back buffer and blitting the new contents to the window. More... | |
An owner-drawn CStatic descendant, providing custom background and text colors and edge styles.
This CStatic descendant also descends from COwnerDraw, and performs custom drawing by implementing OnDrawItem. Custom double-buffering is provided; changes to appearance may not be visible until a repaint is forced by calling UpdateContent.
The member function SubclassStatic reads the sub-classed window's style, and modifies it to include the SS_OWNERDRAW and SS_NOTIFY flags. It also sets or clears the HorzTextAlignment, MultilineEnabled and EndEllipsis member variables as follows:
haCenter
; otherwise, if SS_RIGHT or WS_EX_RIGHT are present, horizontal alignment will be haRight
; otherwise, horizontal alignment will be haLeft
. false
and the horizontal alignment will be set to haLeft
, as described above. true
, horizontal alignment will be haLeft
and MultilineEnabled will be set false
.These modifications are consistent with the behavior of the GDI API DrawText, which is used when painting the control. Note that you can change CODStatic properties to violate the DrawText rules (e.g., set MultilineEnabled and EndEllipsisEnabled both true
), but DrawText will ignore illegal requests.
Vertical alignment settings will be ignored if MultilineEnabled is true
; only vaTop
is valid unless MultilineEnabled is false
.
The text content itself is accessed through the runtime Caption property, NOT the inherited SetWindowText member. The Caption contents are initialized with a call to GetWindowText, so strings loaded through the IDE at design time are faithfully displayed.
Window edge styles defined with window or control style flags (e.g.: SS_ETCHEDFRAME or WS_MODALFRAME) will overwrite edges defined by setting the EdgeStyle property. Use the EdgeStyle property OR windows style flags to define an edge, not both.
If UseThemedStyle is set true
(default: false
), the control will be drawn using the DrawThemeBackground and DrawThemeText API, rather than the older GDI FillRect and DrawText API.
Another point to remember is the BtnFaceBkgnd property ( false
by default). If this is true
(and UseThemedStyle is false
), it will override attempts to change background color, forcing COLOR_BTNFACE.
Finally, the dialog container must reflect WM_DRAWITEM messages back to the control, either with the non-discriminating REFLECT_NOTIFICATIONS_EX, or with something more selective (e.g, REFLECT_NOTIFICATIONS_MSG_ID_FILETERED).
Typical usage is depicted below.
Definition at line 82 of file ODStatic.h.
|
noexcept |
Definition at line 20 of file ODStatic.cpp.
|
virtual |
Definition at line 57 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SubclassStatic | ( | HWND | hWnd | ) |
Subclass a Static Text control.
SubclassStatic also modifies the controls window style to make it owner-drawn and ensure proper notifications are sent by the control, and finally, to set internal state to match as well as possible the design-time window styles flags set for the control.
See the main CODStatic class documentation for more details.
hWnd | Window handle to the Static Text control take over. |
void |
Definition at line 86 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::UnSubclassStatic | ( | ) |
Un-subclass the window and release GDI resources.
Use this method to properly release the subclassed window and other resources.
Definition at line 129 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetBtnFaceBkgnd | ( | bool | value | ) |
Set or clear the UseBtnFaceBkgnd state. A call to UpdateContent may be required to make the new state apparent.
If UseThemedStyle is false and UseBtnFaceBkgnd is true, the control's background will be painted with the current COLOR_BTNFACE value, regardless of the control's BacKColor value. (Note that if UseBtnFaceBkgnd is true, the control will respond to WM_SYSCOLOR_CHANGE and WM_THEMECHANGED messages and will update the color used to paint the background of the control in the event that the user changes the system theme. Text color will NOT automatically change, so if the intent is to have a control with both system button face background and button text colors(COLOR_BTNTEXT), you'll have to handle the WM_SYSCOLORCHANGE and MSG_THEMECHANGED messages yourself, and load the new text color into the control's TextColor property.)
If UseThemedStyle is true, this value is ignored.
value | New bool state. |
void |
Definition at line 175 of file ODStatic.cpp.
bool BIS_WTL_CONTROLS::CODStatic::GetBtnFaceBkgnd | ( | ) | const |
Default: false
.
bool | Current UseBtnFaceBkgnd state. |
Definition at line 152 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetBackColor | ( | COLORREF | value | ) |
Set a new background color. A call to UpdateContent may be required to make the new color visible.
Note that the value set here can be overridden if either BtnFaceBkgnd or UseThemedStyle are true.
value | New background color. |
void |
Definition at line 207 of file ODStatic.cpp.
COLORREF BIS_WTL_CONTROLS::CODStatic::GetBackColor | ( | ) | const |
Default: COLOR_BTNFACE
.
COLORREF | Current BackColor. |
Definition at line 192 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetTextColor | ( | COLORREF | value | ) |
Set a new text color. A call to UpdateContent may be required to make the new color visible.
Note that the value set here can be overridden if UseThemedStyle is true.
value | The new text color. |
void |
Definition at line 240 of file ODStatic.cpp.
COLORREF BIS_WTL_CONTROLS::CODStatic::GetTextColor | ( | ) | const |
Default: COLOR_WINDOWTEXT
.
COLORREF | Current TextColor. |
Definition at line 225 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetCaption | ( | LPCTSTR | text | ) |
Set a new string to display. A call to UpdateContent may be required to make the new caption visible.
The Caption contents will be initialized with a call to GetWindowText, but changes to the displayed text after the control is subclassed must be made through the Caption property; SetWindowText will have no effect.
text | The new text to display. |
void |
Definition at line 274 of file ODStatic.cpp.
std::basic_string< TCHAR > BIS_WTL_CONTROLS::CODStatic::GetCaption | ( | ) | const |
Default: "".
std::basic_string<TCHAR> | Current Caption content. |
Definition at line 258 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetMultilineEnabled | ( | bool | value | ) |
If false
, the DT_SINGLELINE flag will be included in calls to DrawText (or DrawThemeText).
A call to UpdateContent may be required to make changes visible.
See the documentation for the GDI DrawText API for more information.
value | Set/clear internal flag used to wrap text to multiple lines. |
void |
Definition at line 307 of file ODStatic.cpp.
bool BIS_WTL_CONTROLS::CODStatic::GetMultilineEnabled | ( | ) | const |
Default: false
.
bool | Current MultiLineEnabled state. |
Definition at line 291 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetEndEllipsisEnabled | ( | bool | value | ) |
If true, the DT_END_ELLIPSIS flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible.
See the documentation for the GDI DrawText API for more information.
value | New bool state. |
void |
Definition at line 340 of file ODStatic.cpp.
bool BIS_WTL_CONTROLS::CODStatic::GetEndEllipsisEnabled | ( | ) | const |
Default: false
.
bool | Current EndEllipsisEnabled state. |
Definition at line 324 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetPathEllipsisEnabled | ( | bool | value | ) |
If true, the DT_PATH_ELLIPSIS flag will be included in calls to DrawText (or DrawThemeText). A call to UpdateContent may be required to make changes visible.
See the documentation for the GDI DrawText API for more information.
value | New bool state. |
void |
Definition at line 373 of file ODStatic.cpp.
bool BIS_WTL_CONTROLS::CODStatic::GetPathEllipsisEnabled | ( | ) | const |
Default: false
.
bool | Current PathEllipsisEnabled state. |
Definition at line 357 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetHorzTextAlignment | ( | CHorzAlignment | value | ) |
The CHorzAlignment member variable state will result in either the DT_CENTER, DT_LEFT or DT_RIGHT flag being included in calls to DrawText (or DrawThemeText), as appropriate. A call to UpdateContent may be required to make changes visible.
See the documentation for the GDI DrawText API for more information.
value | New CHorzAlignment. |
void |
Definition at line 407 of file ODStatic.cpp.
CHorzAlignment BIS_WTL_CONTROLS::CODStatic::GetHorzTextAlignment | ( | ) | const |
Default: CHorzAlignment::haMiddle
.
CHorzAlignment | Current Horizontal Alignment. |
Definition at line 390 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetVertTextAlignment | ( | CVertAlignment | value | ) |
The CVertAlignment member variable state will result in either the DT_BOTTOM, DT_TOP or DT_VCENTER flag being included in calls to DrawText (or DrawThemeText), as appropriate. A call to UpdateContent may be required to make changes visible.
See the documentation for the GDI DrawText API for more information.
value | New CVertAlignment. |
void |
Definition at line 442 of file ODStatic.cpp.
CVertAlignment BIS_WTL_CONTROLS::CODStatic::GetVertTextAlignment | ( | ) | const |
Default: CVertAlignment::vaLeft
.
CVertAlignment | Current Vertical Alignment. |
Definition at line 425 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetEdgeStyle | ( | CEdgeStyle | style | ) |
The EdgeStyle state determines the type of graphic boundary indicator surrounding the control in it's parent dialog or property page.
Note that window or control style flags such as WS_MODALFRAME or SS_ETCHEDFRAME will result in the owner-drawn edges being overwritten. Use either the EdgeStyle property or window/control style flags to define a control's edge style, but not both.
style |
void |
Definition at line 477 of file ODStatic.cpp.
CEdgeStyle BIS_WTL_CONTROLS::CODStatic::GetEdgeStyle | ( | ) | const |
Default: CEdgeStyle::esLine
.
CEdgeStyle | Current EdgeStyle. |
Definition at line 459 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetVerticalMargin | ( | int | margin | ) |
Sets top and bottom text margin inside window edge. A call to UpdateContent may be required to make changes visible.
margin |
void |
Definition at line 508 of file ODStatic.cpp.
int BIS_WTL_CONTROLS::CODStatic::GetVerticalMargin | ( | ) | const |
Default: 0.
int | The current Vertical Margin. |
Definition at line 494 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetHorizontalMargin | ( | int | margin | ) |
Sets left and right text margin inside window edge. A call to UpdateContent may be required to make changes visible.
margin |
void |
Definition at line 539 of file ODStatic.cpp.
int BIS_WTL_CONTROLS::CODStatic::GetHorizontalMargin | ( | ) | const |
Default: 0.
int | The current Horizontal Margin. |
Definition at line 525 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::UseThemedStyle | ( | bool | val | ) |
If true
, content will be painted using DrawThemeBackground and DrawThemeText, rather than the older FillRect and DrawText APIs.
A call to UpdateContent may be required to make changes visible.
Definition at line 570 of file ODStatic.cpp.
bool BIS_WTL_CONTROLS::CODStatic::IsUsingThemedStyle | ( | ) | const |
Default: false
.
bool | The current UseThemedStyle state. |
Definition at line 556 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetThemedBackgroundStyle | ( | CThemedBackgroundStyle | val | ) |
Set the ThemedBackgroundStyle to a new value.
The CThemedBackgroundStyle enumerants correspond to select TaskDialog Parts, as indicated below:
• CThemedBackgroundStyle::tbPrimaryPanel | TDLG_PRIMARYPANEL |
• CThemedBackgroundStyle::tbMainInstructionPane | TDLG_MAININSTRUCTIONPANE |
• CThemedBackgroundStyle::tbContentPane | TDLG_CONTENTPANEL |
• CThemedBackgroundStyle::tbSecondaryPanel | TDLG_SECONDARYPANEL |
• CThemedBackgroundStyle::tbControlPane | TDLG_CONTROLPANE |
A call to UpdateContent may be required to make changes visible.
For more information, see Parts and States in the MSDN Windows Controls Visual Styles Reference.
val | The new CThemedBackgroundStyle. |
void |
Definition at line 620 of file ODStatic.cpp.
CThemedBackgroundStyle BIS_WTL_CONTROLS::CODStatic::GetThemedBackgroundStyle | ( | ) | const |
Default: tbMainInstructionPane
.
CThemedBackgroundStyle | The current ThemedBackStyle. |
Definition at line 587 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::SetThemedTextStyle | ( | CThemedTextStyle | val | ) |
Set the ThemedTextStyle to a new value.
The CThemedTextStyle enumerants correspond to select TextStyle Parts and States, as indicated below:
Enumerant | Part | Style |
• CThemedTextStyle::ttMainInstruction | TEXT_MAININSTRUCTION | 0 |
• CThemedTextStyle::ttInstruction | TEXT_INSTRUCTION | 0 |
• CThemedTextStyle::ttBodyTitle | TEXT_BODYTITLE | 0 |
• CThemedTextStyle::ttBodyText | TEXT_BODYTEXT | 0 |
• CThemedTextStyle::ttSecondaryText | TEXT_SECONDARYTEXT | 0 |
• CThemedTextStyle::ttLabel | TEXT_LABEL | 0 |
• CThemedTextStyle::ttControlLabel_Normal | TEXT_CONTROLLABEL | TS_CONTROLLABEL_NORMAL |
• CThemedTextStyle::ttControlLabel_Disabled | TEXT_CONTROLLABEL | TS_CONTROLLABEL_DISABLED |
A call to UpdateContent may be required to make changes visible.
For more information, see Parts and States in the MSDN Windows Controls Visual Styles Reference.
val | The new CThemedTextStyle. |
void |
Definition at line 677 of file ODStatic.cpp.
CThemedTextStyle BIS_WTL_CONTROLS::CODStatic::GetThemedTextStyle | ( | ) | const |
Default: ttMainInstruction
.
CThemedTextStyle | The current ThemedTextStyle. |
Definition at line 637 of file ODStatic.cpp.
void BIS_WTL_CONTROLS::CODStatic::UpdateContent | ( | ) |
Wraps calls to Invalidate and UpdateWindow, forcing a repaint, updating the back buffer and blitting the new contents to the window.
Definition at line 693 of file ODStatic.cpp.